package com.zbl.controller;


import javax.annotation.Resource;

import com.github.pagehelper.PageInfo;
import com.zbl.entity.User;
import com.zbl.service.UserService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@EnableAutoConfiguration
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
    public User getUser(@PathVariable long id) throws Exception {
        return this.userService.getUserById(id);
    }

    @RequestMapping(value="", method = RequestMethod.GET, produces="application/json")
    public PageInfo<User> listUser(
            @RequestParam(value="page", required=false, defaultValue="1") int page,
            @RequestParam(value="page-size", required=false, defaultValue="5") int pageSize){
        List<User> result = userService.listUser(page, pageSize);
        // PageInfo包装结果，返回更多分页相关信息
        PageInfo<User> pi = new PageInfo<User>(result);
        return pi;
    }

}
